#include "UnitTest++.h"
#include "Trie.h"
#include "Dictionary.h"

TEST(ShouldAddAnElement)
{
    // arrange
    Trie<int> trie;
    int expectedValue = 4;
    int value = 4;

    // act
    trie.addWord("hello", value);
    int valueFound = *(trie.search("hello"));

    // assert
    CHECK_EQUAL(expectedValue, valueFound);
}

TEST(ShouldAddTwoDifferentKeyWords)
{
    // arrange
    Trie<int> trie;
    int value1 = 1;
    int value2 = 2;

    // act
    trie.addWord("hello", value1);
    trie.addWord("world", value2);

    int value1Found = *(trie.search("hello"));
    int value2Found = *(trie.search("world"));

    // assert
    CHECK_EQUAL(value1, value1Found);
    CHECK_EQUAL(value2, value2Found);
}

TEST(ShouldNotAddAnExistingWord)
{
    // arrange
    Trie<int> trie;
    int firstValue = 1;
    int secondValue = 2;

    // act
    trie.addWord("hello", firstValue);
    trie.addWord("hello", secondValue);

    int retrievedValue = *(trie.search("hello"));

    // assert
    CHECK_EQUAL(firstValue, retrievedValue);
}

TEST(ShouldAddASimilarWord)
{
    // arrange
    Trie<int> trie;
    int firstValue = 3;
    int secondValue = 4;

    // act
    trie.addWord("hilarious", firstValue);
    trie.addWord("hippie", secondValue);

    int retrievedFirstValue = *(trie.search("hilarious"));
    int retrievedSecondValue = *(trie.search("hippie"));

    // assert
    CHECK_EQUAL(firstValue, retrievedFirstValue);
    CHECK_EQUAL(secondValue, retrievedSecondValue);
}

TEST(ShouldAddSimilarSentences)
{
    // arrange
    Trie<int> trie;
    int firstValue = 3;
    int secondValue = 4;

    // act
    trie.addWord("hi everyone", firstValue);
    trie.addWord("hi there hippies", secondValue);

    int retrievedFirstValue = *(trie.search("hi everyone"));
    int retrievedSecondValue = *(trie.search("hi there hippies"));

    // assert
    CHECK_EQUAL(firstValue, retrievedFirstValue);
    CHECK_EQUAL(secondValue, retrievedSecondValue);
}

TEST(shouldModifyFoundElement)
{
    // arrange
    Trie<std::string> trie;
    std::string expectedValue = "nada";
    std::string value = "jorge";

    // act
    trie.addWord("hello", value);
    std::string* valueFound = trie.search("hello");
    *valueFound = "nada";
    std::string* secondValueFound = trie.search("hello");

    // assert
    CHECK_EQUAL(expectedValue, *secondValueFound);
}